package com.qibao.toolkit.exception.strategy.impl;

import com.qibao.toolkit.exception.strategy.AbstractExceptionHandleStrategy;
import com.qibao.toolkit.exception.strategy.BaseExceptionHandleStrategyAware;
import com.qibao.toolkit.exception.strategy.ExceptionHandleType;
import com.qibao.toolkit.web.ResponseModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.HttpRequestMethodNotSupportedException;

/**
 * @author wangcheng
 * @version $Id: MethodNotSupportHandlerStrategy.java, v0.1 2018/9/28 10:01 wangcheng Exp $$
 */
@ExceptionHandleType(HttpRequestMethodNotSupportedException.class)
public class MethodNotSupportHandlerStrategy extends AbstractExceptionHandleStrategy implements
        BaseExceptionHandleStrategyAware {

    private static final Logger logger = LoggerFactory.getLogger(MethodNotSupportHandlerStrategy.class);

    @Override
    public ResponseModel doHandle(Throwable throwable) {
        logger.error(throwable.getMessage(), throwable);
        return ResponseModel.ERROR(HttpStatus.METHOD_NOT_ALLOWED.value(), throwable.getMessage());
    }
}
